﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_Testimonial_TestmonialList : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage();
    private int nPageSize = 14;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.initDataPaging();
        if (!IsPostBack)
        {
            this.setTitle();
            this.BindData(1);
        }
    }
    protected void setTitle()
    {
        lblWarning.Text = MessagesAlert.SEARCH_NO_ITEM[nDefaultLanguage];

        int nSearchType = ConvertData.ConvertToInt(Request.QueryString[Config.SEARCH_TYPE]);
        lblCategoryName.Text = MultipleLanguage.TESTIMONIAL[nCurrentLang - 1];
    }
    private void BindData(int CurrentPageIndex)
    {
        try
        {
            Testimonial objTestimonial = new Testimonial();
            DataTable dtb = new DataTable();
            int nPageCount = 0;
            dtb = objTestimonial.Search(1, nPageSize, ref nPageCount);
            rptTestimonial.DataSource = dtb;
            rptTestimonial.DataBind();
            Pager.ItemCount = nPageCount;

            VisiblePaging(nPageCount);
            if (dtb.Rows.Count > 0)
                tblWarning.Visible = false;
            else
                tblWarning.Visible = true;
        }
        catch
        {
            Response.Redirect("~/Default.aspx");
        }
    }
    protected void rptTestimonial_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
          
            Literal ltrTestimonial = (Literal)e.Item.FindControl("ltrTestimonial");
            Label lblTitle = (Label)e.Item.FindControl("lblTitle");
            Image imgTestimonial = (Image)e.Item.FindControl("imgTestimonial");

            imgTestimonial.ImageUrl = Config.ROOT + Config.IMAGE_TESTIMONIAL_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            ltrTestimonial.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TestimonialContent"));
            lblTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));
           
        }
    }
    
    public string GetCurrentPageName()
    {
        string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
        System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
        string sRet = oInfo.Name;
        return sRet;
    }
    private void initDataPaging()
    {
        Pager.PageSize = nPageSize;
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        Pager.CurrentIndex = currnetPageIndx;
        this.BindData(currnetPageIndx);
    }
    private void VisiblePaging(int intPagecount)
    {
        if (intPagecount > nPageSize)
            Pager.Visible = true;
        else
            Pager.Visible = false;
    }
}
